
"""
Created on Tue Feb 19 14:55:43 2013

@author: aponteeduarddo@gmail.com
Copyright Eduardo Aponte 2013.
"""

from mex_binder import binder_py

eyelink_send_message = binder_py('mx_eyelink_send_message')
eyelink_send_message.mx_c.headers = ['<eyelink.h>','"mex.h"']
eyelink_send_message.bindo += []
eyelink_send_message.mx_c.code = \
"""
INT16 _main( char FARTYPE *ops )
{
    return eyelink_send_message( ops );
}

void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    INT16 code;
    char FARTYPE *elb;
    double *status;
    mwSize td[] = {1,1};
    
    /* Verify input arguments. */
    if(nrhs != 1 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 1 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
    
    if ( mxIsChar(*prhs) != 1)
      mexErrMsgTxt( "msg must be a string.");
      
    elb  = mxArrayToString(*prhs);
    
    if(elb == NULL) 
      mexErrMsgTxt("Could not convert input to string.");
   
    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status = mxGetPr(plhs[0]);
 
    *status = (double ) _main( elb );    
    mxFree( elb );    
    return;
}


"""

eyelink_send_message.mx_c.mdoc = \
"""function [status ] = mx_eyelink_send_message( msg )
%MX_EYELINK_SEND_MESSAGE Sends a text message the connected eye tracker. The 
% text will be added to the EDF file.
%
% Parameters:
% msg 	Text to send to the tracker.
% Returns:
% 0 if no error, else link error code.
%
"""
eyelink_send_message.write_c()
eyelink_send_message.write_m()
eyelink_send_message.compile()
eyelink_send_message.write_sh()

